package com.rainbow.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.rainbow.entity.Result;
import com.rainbow.entity.Salary;
import com.rainbow.service.EmployeeService;
import com.rainbow.service.SalaryService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 工资账套配置
 */
@RestController
@RequestMapping("/salary/sob")
public class SalaryController {
    @Autowired
    SalaryService salaryService;
    @Autowired
    EmployeeService empService;

    @RequestMapping(value = "/salary", method = RequestMethod.POST)
    public Result<T> addSalaryCfg(Salary salary) {
        if (salaryService.addSalary(salary) == 1) {
            return Result.successResult("添加成功!");
        }
        return Result.errorResult("添加失败!");
    }

    @RequestMapping(value = "/salary", method = RequestMethod.GET)
    public List<Salary> salaries() {
        return salaryService.getAllSalary();
    }

    @RequestMapping(value = "/salary", method = RequestMethod.PUT)
    public Result<T> updateSalary(Salary salary) {
        if (salaryService.updateSalary(salary) == 1) {
            return Result.successResult("更新成功!");
        }
        return Result.errorResult("更新失败!");
    }

    @RequestMapping(value = "/salary/{ids}", method = RequestMethod.DELETE)
    public Result<T> deleteSalary(@PathVariable String ids) {
        if (salaryService.deleteSalary(ids) == 1) {
            return Result.successResult("删除成功!");
        }
        return Result.errorResult("删除失败!");
    }

}
